﻿using System;
using System.Diagnostics;
using System.IO;
using Topshelf;

namespace ResharperLicenseService
{
    public class LicenseService : ServiceControl
    {
        public Process WorkstationProcess = null;
        public bool Start(HostControl hostControl)
        {
        
            Console.WriteLine("授权服务正在启动");

            var exename = Environment.Is64BitOperatingSystem ? "IntelliJIDEALicenseServer_windows_amd64.exe" : "IntelliJIDEALicenseServer_windows_386.exe";
            WorkstationProcess = new Process
            {
                StartInfo =
                {
                    FileName = Path.Combine(AppDomain.CurrentDomain.BaseDirectory,"IntelliJIDEALicenseServer(v1.3)",
                        exename),
                    CreateNoWindow = false,
                    UseShellExecute = false,
                   
                }
            };
            WorkstationProcess.Start();
            Console.WriteLine($"{DateTime.Now.ToString("G")}作业调度服务启动成功");
            return true;
        }

        public bool Stop(HostControl hostControl)
        {
            Console.WriteLine($"{DateTime.Now.ToString("G")}作业调度服务停止成功");
            return true;
        }

        public bool Pause(HostControl hostControl)
        {
            Console.WriteLine($"{DateTime.Now.ToString("G")}作业调度服务暂停成功");
            return true;
        }

        public bool Continue(HostControl hostControl)
        {
            Console.WriteLine($"{DateTime.Now.ToString("G")}作业调度服务恢复成功");
            return true;
        }
    }
}